package com.qckj.amz.controller;

import com.qckj.amz.domain.ConfigAttrAtch;
import com.qckj.amz.service.IConfigAttrAtchService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 附加属性维护Controller
 *
 * @author luchuan
 * @since 1.0 2022-01-10
 */
@RestController
@RequestMapping("/amz/configAttrAtch")
public class ConfigAttrAtchController extends BaseController {
    @Autowired
    private IConfigAttrAtchService configAttrAtchService;

    /**
     * 查询附加属性维护列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configAttrAtch:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConfigAttrAtch configAttrAtch) {
        Page<ConfigAttrAtch> page = configAttrAtchService.findConfigAttrAtchPage(configAttrAtch);
        return getDataTable(page);
    }

    /**
     * 导出附加属性维护列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configAttrAtch:export')")
    @Log(title = "附加属性维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConfigAttrAtch configAttrAtch) {
        List<ConfigAttrAtch> list = configAttrAtchService.findConfigAttrAtchList(configAttrAtch);
        ExcelUtil<ConfigAttrAtch> util = new ExcelUtil<>(ConfigAttrAtch.class);
        return util.exportExcel(list, "configAttrAtch");
    }

    /**
     * 获取附加属性维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:configAttrAtch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(configAttrAtchService.findById(id));
    }

    /**
     * 新增附加属性维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configAttrAtch:add')")
    @Log(title = "附加属性维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigAttrAtch configAttrAtch) {
        AjaxResult res = configAttrAtchService.save(configAttrAtch);
        return res;
    }

    /**
     * 修改附加属性维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configAttrAtch:edit')")
    @Log(title = "附加属性维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigAttrAtch configAttrAtch) {
        AjaxResult res = configAttrAtchService.save(configAttrAtch);
        return res;
    }

    /**
     * 删除附加属性维护
     */
    @PreAuthorize("@ss.hasPermi('amz:configAttrAtch:remove')")
    @Log(title = "附加属性维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        configAttrAtchService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * 通过产品分类获取附加属性配置信息
     * @param productCategory
     * @return
     */
    @RequestMapping(value = "/getConfigAttrAtchByProductCategory")
    public AjaxResult getConfigAttrAtchByProductCategory(@RequestBody String productCategory) {
        List<ConfigAttrAtch> res = configAttrAtchService.getConfigAttrAtchByProductCategory(productCategory);
        return AjaxResult.success(res);
    }


}
